<?php

/**
 * Subclass for representing a row from the 'conf_registration' table.
 *
 * 
 *
 * @package lib.model
 */ 
class Registration extends BaseRegistration
{
  
  
  public function storeInitialRegistrationInformation ($conferenceID, $registrant, $selectedSessionIDs=null, $selectedSpecialEventIDs = null, $totalConferenceFee)
  {
    /*
    save to store all registration information
    1. create new registration entry will values from parameter
    2. save in sessionregistration
    3. save in specialeventregistration
    */

    $registrantID = $registrant->getId();
    //$registration = new Registration();

    //$registration->setId($this->getRequestParameter('id'));
    $this->setRegistrantId($registrantID);
    $this->setConferenceId($conferenceID);
    $this->setTotalFee($totalConferenceFee);
    $this->setTotalPaid($totalConferenceFee);
    $this->setPaymentVerified(0);
    
    $this->save();

    
    $registrationID = $this->getId();
    
    //save to sessionRegistration
    if ($selectedSessionIDs && count($selectedSessionIDs) > 0)
    {
      foreach ($selectedSessionIDs as $selectedSessionID)
      {
        $session_registration=new SessionRegistration();
        
        $session_registration->setSessionId($selectedSessionID);
        $session_registration->setRegistrationId($registrationID);
        
        $session_registration->save();
      }
    }

    //save to specialeventregistration
    if ($selectedSpecialEventIDs && count($selectedSessionIDs) > 0)
    {
      foreach ($selectedSpecialEventIDs as $selectedSpecialEventID)
      {
        $special_event_registration=new SpecialEventRegistration();
        
        $special_event_registration->setSpecialeventId($selectedSpecialEventID);
        $special_event_registration->setRegistrationId($registrationID);
        
        $special_event_registration->save();
      }
    }
    return $this;
  }	
	
  
  public function generateInvoiceNumber($registration)
  {
    //$dateFormatRequired = 'ymdHi';
    $createdAtDate = $registration->getCreatedAt('ymdHi');
    
    $randomNumber = rand ( 1000 , 9999 );
    
    return $createdAtDate.$randomNumber;
  }
  
  
  //gets a donation ammount associated with a registration (front end only allows 1 donation so should be fine)
	public function getDonation(){
        $p = $this->getDonations();
		$tot = 0;
		foreach($p as $d){
			$tot = $tot + $d->getAmount();
		}
        return $tot;
	}


  

  


  
}
